package io.renren.modules.headmaster.service.impl;

import io.renren.common.utils.ShiroUtils;
import io.renren.modules.common.entity.CensusEntity;
import io.renren.modules.headmaster.dao.MasterCensusDao;
import io.renren.modules.headmaster.service.MasterCensusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.Objects;

/**
 * @author wks
 * @date 2022/2/10 15:54
 */
@Service
public class MasterCensusServiceImpl implements MasterCensusService {

    @Autowired
    MasterCensusDao masterCensusDao;

    @Override
    public Integer studentNum(Long classId) {
        return masterCensusDao.studentNum(classId);
    }

    @Override
    public Integer punchStudentNum(Date date, Long classId) {
        return masterCensusDao.punchStudentNum(date, classId);
    }

    @Override
    public CensusEntity sectorList(Date date) {
        if (Objects.isNull(date)) {
            date = new Date(System.currentTimeMillis());
        }
        Long classId = ShiroUtils.getUserEntity().getClassId();
        CensusEntity censusEntity = new CensusEntity();
        //当前日期班级下打卡人数
        Integer punchStudentNum = punchStudentNum(date, classId);
        //学生总人数
        Integer studentNum = studentNum(classId);
        //当前日期班级下未打卡人数
        int noPunchStudentNum = studentNum - punchStudentNum;

        censusEntity.setNoPunchStudent(noPunchStudentNum);

        censusEntity.setPunchStudent(punchStudentNum);

        return censusEntity;
    }
}
